package com.example.myapplication.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModelProvider;

import com.example.myapplication.common.Res;
import com.example.myapplication.viewModel.LoginViewModel;
import com.example.myapplication.databinding.LoginBinding;

import com.example.myapplication.R;

import cn.hutool.core.util.StrUtil;

public class LoginActivity extends AppCompatActivity {

//    private Context context;

    LoginBinding binding; //自动生成的  布局文件
    LoginViewModel loginViewModel; //状态

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        context = getApplicationContext();

        //官方初始化 不可更改
        loginViewModel = new ViewModelProvider(this,new ViewModelProvider.NewInstanceFactory()).get(LoginViewModel.class);

        //绑定
        binding = DataBindingUtil.setContentView(this,R.layout.login);
        binding.setVm(loginViewModel);
        binding.setLifecycleOwner(this);
    }

    public void click(View view){
//        if(StrUtil.equals(loginViewModel.username.getValue(),"admin")){
//            Toast.makeText(getApplicationContext(),loginViewModel.username.getValue(), Toast.LENGTH_LONG).show();
            Intent intent = new Intent(this,ListActivity.class);
            startActivity(intent);
//        }

    }

}
